package pid

import (
	"fmt"
	"time"
)

func ChargeLoadTrack() {
	battery := Battery{
		SOC:         50, // 初始电池SOC
		ChargePower: 0,  // 初始充电功率
		DesiredSOC:  80, // 目标 SOC
		ChargeRate:  100,
		PID: PID{
			Kp: 0.1,
			Ki: 0.01,
			Kd: 0.1,
		},
		LoadTracking: LoadTrackingControl{
			BasePower:  50,
			MaxPower:   200,
			MinPower:   0,
			Adjustment: 1,
		},
		DemandControl: DemandControl{
			BasePower:       50,
			MaxPower:        200,
			MinPower:        0,
			PowerAdjustment: 0.1,
		},
	}

	fmt.Printf("Initial SOC: %.2f%%\n", battery.SOC)
	currentLoad := 75.0
	for i := 0; i < 110; i++ {
		time.Sleep(1 * time.Second) // 模拟时间流逝
		if currentLoad > 5 {
			currentLoad = 75.0 - float64(i*5) // 模拟负荷需求
		}
		battery.UpdateChargePower(currentLoad, 1) // 更新充电功率
		fmt.Printf("Updated SOC: %.2f%% power:%f\n ", battery.SOC, battery.ChargePower)
	}
}
